當前位置: 首頁> 函數類別大全> opendir

opendir

打開目錄句柄
名稱:opendir
分類:目錄函數
所屬語言:php
一句話介紹:打開目錄句柄。

定義和用法

opendir()函數打開目錄句柄。

實例

打開一個目錄,讀取它的內容,然後關閉:

 <?php
$dir = "/images/" ;

// 打開目錄,然後讀取其內容
if ( is_dir ( $dir ) ) {
  if ( $dh = opendir ( $dir ) ) {
    while ( ( $file = readdir ( $dh ) ) !== false ) {
      echo "filename:" . $file . "<br>" ;
    }
    closedir ( $dh ) ;
  }
}
?>

結果:

 filename: cat.gif
filename: dog.gif
filename: horse.gif

文法

opendir ( path , context ) ;
參數 描述
path 必需。規定要打開的目錄路徑。
context 可選。規定目錄句柄的環境。 context是可修改目錄流的行為的一套選項。
同類函數